<template>
	<view class="" style="">
		<view class="" style="padding: 10px;">
			<view>
				<u-tabs-swiper ref="uTabs" :list="list" :current="current" @change="tabsChange" :is-scroll="false"
					swiperWidth="750"></u-tabs-swiper>
			</view>
			<view class="" style="height: 0rpx;">
			</view>

			<view v-if="current == 0" class="searchbox flex flex-start mt-20">
				<view class="searchimg">
					<image src="../../static/mark/search.png" mode="widthFix" @click="handlesearch()">
					</image>
				</view>
				<view class="selectbox ml-10 flex flex-between">
					<view v-for="item in select_list"
						:class="['plr-20','ptb-12',item.active==true?'selectitem':'selectitem1']"
						@click="navigation(item)">{{item.name}}</view>
				</view>
			</view>

			<view v-if="current == 1" class="searchbox flex flex-start mt-20">
				<view class="searchimg">
					<image src="../../static/mark/search.png" mode="widthFix" @click="handlesearch()">
					</image>
				</view>
				<view class="selectbox ml-10 flex flex-between">
					<view v-for="item in Journalism_list"
						:class="['plr-20','ptb-12',item.active==true?'selectitem':'selectitem1']"
						@click="navigation(item)">{{item.name}}</view>
				</view>
			</view>

			<swiper style="height:900rpx;" :current="swiperCurrent" @transition="transition"
				@animationfinish="animationfinish">
				<swiper-item class="swiper-item" v-for="(item, index) in list" :key="index">
					<scroll-view scroll-y style="height: 1000rpx;width: 100%;" @scrolltolower="onreachBottom">

						<view class="" v-if="current==0">
							<view class="contbox ptb-20">
								<view class="market_list" style="" v-for="item in notice_list"
									@click="tonotice(item.id)">
									<view class="" style="width: 58%;">
										<view class="market_list_title fw" style="">
											{{item.title}}
										</view>
										<view class="flex1 size-20 market_list_category_name" style="">
											<view class="market_list_category_name_left">
												{{item.category_name}}
											</view>
											<view class="">
												{{item.create_time}}
											</view>
										</view>
									</view>
									<view class="rightbox">
										<image class="photo" :src="item.image" mode=""></image>
									</view>
								</view>
							</view>
						</view>


						<view class="contbox ptb-20" v-if="current==1">
							<view class="contentitem ptb-20" v-for="item in journalismarr" @click="toWebsite(item.id)">
								<view class="imgbox">
									<image :src="item.image" mode="widthFix"></image>
								</view>
								<view class="contenttit mt-20 size-26 ">{{item.title}}</view>
								<view class="tipsbox flex">
									<view class="tipsborder plr-10">{{item.category_name}}</view>
									<view class="timebox">{{item.create_time}}</view>
								</view>
							</view>
						</view>
						<view class="" v-if="current==2">
							<view class="putQuestions">
								<view class="putitem pt-30" v-for="item in putarr" @click="toRumor(item)">
									<view class="putUser size-26">
										<view class="userInfo flex">
											<view class="flex flex-start">
												<image mode="" :src="item.head_image==''?yes:item.head_image"
													style="border-radius: 50%;width: 70rpx;height: 70rpx;"></image>

												<view class="">{{item.is_anonymous==0 ? item.uname:'匿名提交'}}</view>

											</view>
											<view class="putTime">{{item.create_time}}</view>
										</view>
										<view class="putCont plr-60 ptb-20">
											<view class="">{{item.remark}}</view>
											<view class="imagearr mt-20">
												<image v-for="item in item.images" :src="item" mode="aspectFit"></image>
											</view>
										</view>
									</view>
									<view class="official mtb-30 flex">
										<image src="../../static/market/zi.png" mode="widthFix"></image>
										官方回复：<view class="reply">{{item.reply}}</view>
									</view>
								</view>
							</view>
							<view class="questionbox white flex pr-30" @click="toquestions">
								<view class="add_question">
									<image src="../../static/mark/k3.png"></image>
								</view>
								我要提问
							</view>
						</view>
					</scroll-view>
				</swiper-item>
			</swiper>
		</view>
		<tab></tab>
	</view>
</template>

<script>
	import {
		globalData
	} from "@/App.vue"
	import tab from "../../components/tab.vue"
	export default {
		components: {

			tab
		},
		data() {
			return {
				putarr: [],
				journalismarr: [],
				Journalism_list: [],
				notice_list: [],
				select_list: [],
				tcount: '',
				name: '',
				price: '',
				showUpImg: true,
				is_focus: '',
				image: "",
				name: '',
				id: 1,
				arrcreator: [],
				// item: 0,
				query: {
					page: 1,
					pagesize: 10,
					search: "",
					time_order: '',
					price_order: '',
				},

				goods_id: [],
				tabs: [],
				// 因为内部的滑动机制限制，请将tabs组件和swiper组件的current用不同变量赋值
				current: 0, // tabs组件的current值，表示当前活动的tab选项
				swiperCurrent: 0, // swiper组件的current值，表示当前那个swiper-item是活动的
				list: [{
						name: '平台公告',
						index: 0,
					},
					{
						name: '新闻发声',
						index: 1,
					},
					{
						name: '辟谣墙',
						index: 2,
					},

				]
			}
		},
		onLoad() {
			let _that = this;
			uni.getSystemInfo({
				success(e) {
					console.log(e.statusBarHeight, '123122222222222222222222');
					if (e.platform == "ios" || e.platform == "devtools") {
						_that.blindBoxheight = e.statusBarHeight + 45;
					} else {
						_that.blindBoxheight = e.statusBarHeight + 50;
					}
				}
			})
			console.log(getApp().globalData);
		},
		onShow(options) {
			this.arr()
			this.discoveryClassification()
			this.newsOccurrence()
			console.log(this.options);
			// this.myCollectlist()
			// 公告初渲染
			// this.$http('api/index/noticeList/', this.query).then(res => {
			// 	this.notice_list = res
			// 	// console.log(this.notice_list);
			// })

		},
		methods: {
			handlesearch() {
				uni.navigateTo({
					url: '/pages/market/marketSearch'
				})
			},
			// 辟谣墙跳转
			toquestions() {
				uni.navigateTo({
					url: '/pages/market/question'
				})
			},
			// 新闻发声列表跳转
			toWebsite(id) {
				console.log(id);
				uni.navigateTo({
					url: '/pages/market/newDetail?id=' + id
				})
			
			},
			// 平台公告列表跳转
			tonotice(id) {
				console.log(id);
				uni.navigateTo({
					url: '/pages/market/noticeDetail?id=' + id
				})
			},
			feedBackList() {
				// 辟谣墙初渲染
				this.$http('api/user/feedBackList', this.query).then(res => {
					res.forEach((item) => {
						this.images = item.images
						// console.log( this.images);
					})
					this.putarr = this.putarr.concat(res)
					this.query.page++
					this.wall = res.length
					console.log(this.wall);
					console.log(this.putarr);
				})
			},
			toRumor(item) {
				var item = JSON.stringify(item)
				uni.navigateTo({
					url: '/pages/market/rumor_detail?item=' + item
				})
			},
			arr() {
				this.$http('api/index/noticeList/', this.query).then(res => {
					this.notice_list = res
					// console.log(this.notice_list);
				})
			},
			// 新闻发生分类
			newsOccurrence() {
				this.$http('api/index/newsCategoryList').then(res => {
					let arr = JSON.parse(JSON.stringify(res))
					arr[0].active = true
					this.Journalism_list = arr
					console.log(this.Journalism_list);
				})
			},
			// 平台公告分类
			discoveryClassification() {
				this.$http('api/index/noticeCategoryList', this.query).then(res => {
					// this.select_list = res
					let arr = JSON.parse(JSON.stringify(res))
					arr[0].active = true
					this.select_list = arr

				})
			},
			// 二级tab点击
			navigation(item) {
				console.log(item);
				if (this.current == 0) {
					this.$http('api/index/noticeList/', {
						category_id: item.id
					}).then(res => {
						this.notice_list = res
						// console.log(this.notice_list);
					})

				} else if (this.current == 1) {
					this.id = item.id
					this.$http('api/index/newsList', {
						category_id: this.id
					}).then(res => {
						this.journalismarr = res

					})
				}


			},

			// },

			// tabs通知swiper切换
			tabsChange(index) {
				this.swiperCurrent = index;
			},
			// swiper-item左右移动，通知tabs的滑块跟随移动
			transition(e) {
				let dx = e.detail.dx;
				this.$refs.uTabs.setDx(dx);
			},
			// 由于swiper的内部机制问题，快速切换swiper不会触发dx的连续变化，需要在结束时重置状态
			// swiper滑动结束，分别设置tabs和swiper的状态
			animationfinish(e) {
				let current = e.detail.current;
				this.$refs.uTabs.setFinishCurrent(current);
				this.swiperCurrent = current;
				this.current = current;
				// console.log(this.current);
				if (current == 0) {
					console.log(0);
					this.arr()
				} else if (current == 1) {
					// 新闻初渲染
					this.$http('api/index/newsList', this.query).then(res => {
						this.journalismarr = res
						console.log(this.journalismarr);
					})

				} else if (current == 2) {
					// 辟谣墙初渲染
					this.$http('api/user/feedBackList', this.query).then(res => {
						res.forEach((item) => {
							this.images = item.images
							// console.log( this.images);
						})
						this.putarr = this.putarr.concat(res)
						this.query.page++
						this.wall = res.length
						console.log(this.wall);
						console.log(res);
					})

				}
			},
			// scroll-view到底部加载更多
			onreachBottom() {}
		}

	}
</script>

<style lang="less" scoped>
	.questionbox {
		// border: 1rpx solid red;
		width: 240rpx;
		height: 70rpx;
		line-height: 70rpx;
		border-radius: 40rpx;
		background: linear-gradient(90deg, #fff, #000);
		position: fixed;
		bottom: 14%;
		right: 8%;

		.add_question {
			width: 70rpx;
			height: 70rpx;
			border-radius: 50%;
			background-color: #000;

			image {
				// border: 1rpx solid red;
				width: 100%;
				height: 100%;
			}
		}
	}

	::v-deep  .u-tabs-scorll-flex {
		width: 200rpx;
	}

	::v-deep  .u-tabs-item {}

	#app {
		flex: 1;
		display: flex;
		flex-direction: column;
	}


	.back {
		color: #FFF;
		margin: -100rpx 0px 0px 20rpx;
		font-size: 36rpx;
	}

	.contbox {
		.contentitem {
			border-bottom: 1rpx solid #E0E0E0;

			.imgbox {
				height: 220rpx;
				overflow: hidden;

				image {
					width: 100%;
				}
			}

			.leftbox {
				.text_title {
					font-weight: 600;
				}

				.tipsbox {
					margin-top: 100rpx;
					font-size: 12rpx;

					.tipsborder {
						border: 1rpx solid rgb(108, 126, 205);
						border-radius: 10rpx;
						color: rgb(108, 126, 205);
						background-color: rgb(239, 246, 255);
					}
				}
			}

			.contenttit {
				overflow: hidden;
				text-overflow: ellipsis;
				white-space: nowrap;
			}

			.tipsbox {
				margin-top: 16rpx;
				font-size: 12rpx;

				.tipsborder {
					border: 1rpx solid rgb(108, 126, 205);
					border-radius: 10rpx;
					color: rgb(108, 126, 205);
					background-color: rgb(239, 246, 255);
				}
			}
		}
	}

	.searchbox {
		.searchimg {
			width: 60rpx;
			height: 40rpx;
			border-right: 1rpx solid #999;

			image {
				width: 40rpx;
			}
		}

		.selectbox {

			.selectitem,
			.selectitem1 {
				font-size: 16rpx;
				color: #999;
				margin: 0 10rpx;
				border-radius: 40rpx;
				background-color: rgb(246, 246, 246);
				width: 140rpx;
				height: 60rpx;
				text-align: center;
			}

			.selectitem {
				color: #fff;
				background-color: rgb(0, 203, 211);
				width: 140rpx;
				height: 60rpx;
				text-align: center;
			}
		}
	}

	::v-deep  .u-action {
		color: #fff !important;
	}

	::v-deep  .u-action-active {
		color: #fff;
	}

	.market_list_category_name_left {
		background-color: #ECECEC;
		width: 130rpx;
		height: 50rpx;
		text-align: center;
		line-height: 50rpx;
		margin: -14rpx 0 0 0;
	}

	.market_list_category_name {
		justify-content: space-between;
		margin: 30rpx 0 0 0;
	}

	.market_list_title {
		height: 80rpx;
		width: 400rpx;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 2;
		overflow: hidden;


	}

	.market_list {
		display: flex;
		justify-content: space-between;
		border-bottom: 3rpx solid #E0E0E0;
		margin: 0px 0px 40px 0;
		height: 180rpx;
	}


	.rightbox {
		width: 260rpx;
		background-color: aqua;
		height: 140rpx;
	}

	.putQuestions {
		.putitem {
			.putUser {
				border-bottom: 1rpx solid rgb(227, 227, 227);

				.userInfo {
					color: #999;

					image {
						width: 40rpx;
						height: 40rpx;
						margin-right: 20rpx;
					}
				}

				.putCont {
					.imagearr {
						;
						display: flex;
						width: 100%;

						image {
							width: 100px;
							height: 100px;
							// position: absolute;
							// top: -50%;
						}
					}
				}
			}

			.official {
				image {
					width: 40rpx;
					height: 40rpx;
					margin-right: 20rpx;
				}

				.reply {
					color: rgb(223, 97, 46);
					display: inline-block;
					white-space: nowrap;
					width: 67%;
					overflow: hidden;
					text-overflow: ellipsis;
				}
			}

		}
	}
</style>
